package com.clouddo.artical.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.ws.rs.Produces;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.clouddo.artical.model.Artical;
import com.clouddo.artical.service.ArticalService;

@RestController
@RequestMapping("/artical")
public class ArticalController {
	
	public ArticalController() {
		// TODO Auto-generated constructor stub
	}
	
	@Autowired
	ArticalService articalService;
	
	@RequestMapping("/list")
	@Produces("application/json;charset=UTF-8")
	@CrossOrigin
	public Map<String, Object> list() {
		List<Artical> userlist = articalService.list();
		Map<String, Object> map = new HashMap<>();
		map.put("results", userlist);
		return map;
	}
	
	@RequestMapping(value = "/save")
	@Produces("application/json;charset=UTF-8")
	@CrossOrigin
    int save(@RequestBody Artical artical) {
		return articalService.save(artical);
	}
	
	@RequestMapping(value="/update")
	@Produces("application/json;charset=UTF-8")
	@CrossOrigin
	int update(@RequestBody Artical artical) {
		return articalService.update(artical);
	}
	
	@RequestMapping(value="/delete")
	@Produces("application/json;charset=UTF-8")
	@CrossOrigin
	int remove(Integer id) {
		return articalService.delete(id);
	}

}
